﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true"
    CodeFile="Grid.aspx.cs" Inherits="_Grid" %>

<asp:Content ID="Contenido" ContentPlaceHolderID="MainContent" runat="server">
    <table id="grid" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll" style="text-align: center;">
    </div>
</asp:Content>
<asp:Content ID="scripts" ContentPlaceHolderID="Javascript" runat="server">

    <script type="text/javascript">
    jQuery(document).ready(function()
      {
        $("#grid").jqGrid(
        {
            datatype: getTareas(),                   
            jsonReader : //jsonReader –> JQGridJSonResponse data.
            {                
                page: "CurrentPage",
                total: "PageCount",
                records: "RecordCount",
                root: "Items",
                repeatitems: false,
                cell: "Items",
                id: "0"               
            },
            colNames:['Id','Descripcion', 'FechaCreacion'],
   	        colModel:[
   		        {name:'Id',index:'Id', width:55, editable:true, edittype:"text"},
   		        {name:'Descripcion',index:'Descripcion', width:90, editable:true, edittype:"textarea"},
   		        {name:'FechaCreacion',index:'FechaCreacion', width:134, editable:true, edittype:"text"}	
   	        ],
   	        rowNum:10,
   	        rowList:[10,20,30],
   	        imgpath: "",
   	        pager: jQuery('#pager'),
   	        sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            caption:"JSON Example",
            editurl:"TareaEditar.aspx"
        }).navGrid('#pager',{edit:true,add:true,del:true});     
              }); 
              
    function getTareas()
    {          
         $.ajax(
                {
                    url: "Paginas/Listas/ListaTareas.aspx/buscarTareas", //PageMethod
                    data: "{}", //Parametros de entrada del PageMethod                   
                    dataType: "json",
                    type: "post",
                    contentType: "application/json; charset=utf-8",
                    complete: function(jsondata, stat)
                    {
                      if (stat == "success")
                      {
                        jQuery("#grid")[0].addJSONData(JSON.parse(jsondata.responseText).d);
                      }
                      else
                        alert(JSON.parse(jsondata.responseText).Message);
                    }
                }
               );
    }
    
   $("#bedata").click(function(){
	var gr = jQuery("#grid").getGridParam('selrow');
	if( gr != null ) jQuery("#grid").editGridRow(gr,{height:280,reloadAfterSubmit:false});
	else alert("Please Select Row");
});
    </script>

</asp:Content>
